package com.church.action;

import java.io.UnsupportedEncodingException;
import java.util.Map;

import com.church.db.Tasklist;
import com.church.services.TasklistServices;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class EditTask extends ChurchActionSupport {
	private TasklistServices tasklistServices;
	private Tasklist tasklist;
	private boolean success;
	public TasklistServices getTasklistServices() {
		return tasklistServices;
	}

	public void setTasklistServices(TasklistServices tasklistServices) {
		this.tasklistServices = tasklistServices;
	}

	public Tasklist getTasklist() {
		return tasklist;
	}

	public void setTasklist(Tasklist tasklist) {
		this.tasklist = tasklist;
	}

public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	//	public String execute() {
//		ActionContext actionContext = ActionContext.getContext();
//		Map session = actionContext.getSession();
//		String userGroup = (String) session.get("USER_GROUP");
//		String userType=(String) session.get("USER_TYPE");
//		if (userGroup != null&&userType!=null) {
//			if (!userGroup.equals("user")&&userType.equals("admin")) {
//				tasklistServices.updateTask(tasklist);
//				tasklistServices.addTask(tasklist);
//			}
//		}
//		return "success";
//	}
	public String addTask()
	{
		if(tasklist!=null)
		{
			tasklist.setState("START");
			success=tasklistServices.addTask(tasklist).equals("success");
		
		}
		return SUCCESS;
	}
	public String stopTask()
	{
		if(tasklist!=null)
		{
			success=tasklistServices.removeTask(tasklist.getId()).equals("success");
		}
		return SUCCESS;
	}
	
}
